package com.itheima.sky.dao;

import com.itheima.sky.dto.DishDto;
import com.itheima.sky.pojo.Dish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description DishMapper
 * @Author jiangning
 * @Date 2024-06-29
 */
@Mapper
public interface DishMapper {
    @Select("select * from dish where category_id = #{cateId} and status = #{status};")
    List<Dish> getDishListByCategoryId(BigDecimal cateId,Integer status);

    @Select("SELECT COUNT(*) FROM dish WHERE category_id=#{categoryId}")
    long findDishCountByCategoryId( Long id);

    //pan

    //根据名字查找菜品
    List<Dish> findByNameP(String name);

    long findDishCountByCategoryIdP(Long id);

    //根据id查找菜品
    @Select("select * from dish where id=#{id}")
    Dish findById(Long id);

    void updateByIdP(DishDto dishDto);

    @Insert("insert into  dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void save(DishDto dishDto);

    /**
     * 查找菜品id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<Dish> findByCategoryId(Long categoryId);

    /**
     * 通过查询菜品名称来查找信息
     * @param name
     * @return
     */
    List<Dish> findDishAll(Long categoryId ,String name);

    /**
     *
     * @return
     */
    @Select("select * from dish")
    List<Dish> findAll();

}
